//less
require('./login_.less')
//公共样式
require('../../assets/css/index.less')
//axios
const request =require('../../utils/request')
//获取元素
function $(arr) {
    return document.querySelector(arr)
 }
 
let reg1 = /^1[3|4|5|6|7|8|9][0-9]{9}$/;  //正则表达式 账号
let reg2 = /^[0-9]{6}$/;// 正则表达式  密码
window.onload=()=>{
     
         $('.btn').addEventListener('click',function(){
            if(reg1.test($('.empn').value)&&reg2.test($('.password').value)){
               request.post('/api/user/login',{  //发请求
                  account: $('.empn').value,
                  password: $('.password').value
                 }).then(res=>{
                  // console.log(res.data);
                  //解构
                  const {data,errno}=res.data
                  if(errno===0){
                        localStorage.setItem('token','Bearer '+data.token)
                        $('.regs').style.opacity = 0.8   
                        $('.regs_').innerHTML='登录成功'
                        $('.regs_1').innerHTML = '√'
                        setInterval(function () {
                           location.href = './home.html'
                        }, 2000)
                  }else{
                     $('.regs').style.opacity = 0.8   
                     $('.regs_').innerHTML='请输入正确账号'
                  }
                 })
            }else{
               $('.regs').style.opacity = 0.8//显示
               $('.regs_').innerHTML='请输入正确账号密码'
            }
           })
        
       
$('.regs').addEventListener('click', () => {
   $('.regs').style.opacity = 0

})
}



